<template>
  <div>
    <RouterBreadCrumb :dataList="breadCrumgDataList"/>
    <FileViewNewCard :listData="listData"/>
  </div>
</template>

<script>
  import RouterBreadCrumb from "../../components/BreadCrumb/RouterBreadCrumb/index";
  import FileViewNewCard from "../../components/FileViewNew/FileViewNewCard";

  //该㢟用来显示文件列表
  export default {
    name: "FileViewRouter",
    components: {FileViewNewCard, RouterBreadCrumb},
    data() {
      return {
        listData: [],

        absPath: '/',
        //1 表示文件列表， 2 表示视频， 3 表示图片
        fileTypeFlag: 1
        // absPath: '/',
        // //
        // currViewFlag: 1,
        // //视频url
        // videoUrl: ''
      }
    },
    computed: {
      breadCrumgDataList: function () {
        if(this.absPath == null || this.absPath.length === 0 || this.absPath.replace(/(^s*)|(s*$)/g, "").length === 0
          || '/' === this.absPath) {
          // return ['Home', '/'];
          return [{name: 'Home', absPath: '/'}];
        }
        let arr = this.absPath.split('/');
        //删除arr中的空格和换行
        arr.unshift('Home');
        for (let i = arr.length; i >= 0; i--) {
          if(arr[i] == null || arr[i] === '') {
            arr.splice(i, 1);
          }
        }
        //arr转成item数组
        let itemArr = [];
        let currAbsAllPath = '/';
        for (let i = 0; i < arr.length; i++) {
          currAbsAllPath += arr[i];
          itemArr.push({
            name: arr[i],
            absPath: currAbsAllPath
          });
        }
        // console.log(itemArr);
        return itemArr;
      }
    },
    methods: {
      //获取子文件列表
      getChildFileList() {
        this.absPath = 'absPath' in this.$route.params ? this.$route.params.absPath : '/';
        this.fileTypeFlag = 'fileTypeFlag' in this.$route.params ? this.$route.params.fileTypeFlag : 1;
        this.$api.fileView.getChildFileList({
          urlAbsPath: this.absPath
        }).then(res => {
          this.listData = res.data.data;
        });
      }
    },
    mounted() {
      // this.absPath = this.$route
      // console.log('=============')
      // console.log(this.$route.params)
      // console.log('=============')


      this.getChildFileList()
    },
    watch: {
      '$route'(to, from) {
        if (to.query) {
          this.getChildFileList();
        }
      }
    }
  }
</script>

<style scoped>
</style>
